<template>
    <div class='photoinfo'>
        <div class="title">
            <h4 v-text='info.title'></h4>
            <p>{{info.add_time | datefmt('YYYY-MM-DD')}} {{info.click}}次浏览</p>
            <p class="line"></p>
        </div>
        <!--缩略图-->
        <div class="mui-content">
            <ul class="mui-table-view mui-grid-view mui-grid-9">
                <li  v-for="(item,index) in imgs" class="mui-table-view-cell mui-media mui-col-xs-4 mui-col-sm-3">
                    <img class="preview-img"  :src="item.src" height="100" @click="$preview.open(index,imgs)">
                </li>
            </ul>
            <!--图片详情- 摘要部分-->
            <p v-html="info.content"></p>
        </div>
        <!--实现评论组件-->
        <comment :id='id'></comment>
    </div>
</template>
<script>
    import comment from '../subcom/comment.vue';
    import common from '../../kits/common.js';
    import { Toast } from 'mint-ui';
    export default{
        components: {
            comment  //注册评论组件
        },
        data(){
            return {
                id:0,
                info:[],
                imgs:[]
            }
        },
        created(){
            //			1.0 获取url传入的id参数值赋值给data中的id属性
            this.id = this.$route.params.id;
            this.getimageInfo();
            this.getthumimages();
        },
        methods: {
            getimageInfo(){
                var url= common.apidomain + '/api/getimageInfo/'+this.id;
                this.$http.get(url).then(function (res) {
                    this.info=res.body.message[0];
                })
            },
            getthumimages(){
                var url= common.apidomain + '/api/getthumimages/'+this.id;
                this.$http.get(url).then(function (res) {
                    var body = res.body;

                    body.message.forEach(function(item){
//						当前所有图片不管有多大都设置为宽高为400，就会导致图片失真了，所以应该按照图片的实际尺寸来设置
                        var img = document.createElement('img');
                        img.src = item.src;
                        item.h = img.height;
                        item.w = img.width;
                    });
                    this.imgs=body.message;
                })
            }
        }
    }
</script>
<style scoped>
    .title h4 {
        color: #0094ff;
    }

    .title p {
        color: rgba(0, 0, 0, 0.5);
    }

    .title, #content {
        padding: 5px;
    }
    /*图片详情样式*/
    #desc{
        padding: 10px;
    }
    #desc  .title h4{
        color: #0094ff;
    }

    #desc .title p{
        color:rgba(0,0,0,0.4);
        margin-top: 10px;
    }

    #desc .title .line{
        width: 100%;
        height: 1px;
        border-bottom: 1px solid rgba(0,0,0,0.4);
    }

    .mui-content,.mui-content ul{
        background-color: #fff;
    }
    .mui-grid-view.mui-grid-9 .mui-table-view-cell{
        border-right:0px;
        border-bottom:0px;
    }
    .mui-grid-view.mui-grid-9{
        border-top:0px;
        border-left:0px;
    }

    /* 9宫格缩略图的样式*/
    .mui-content img{
        width: 100px;
        height: 100px;
    }

</style>